package org.fuxia.im.listeners;

import java.awt.Component;

import javax.swing.JDialog;

import org.fuxia.im.common.ClientConst;
import org.fuxia.im.common.ClientContext;
import org.fuxia.im.common.CommonDialog;
import org.fuxia.im.core.entries.ECResponse;
import org.fuxia.im.core.listeners.Listener;

public class RegistUserResponseListener implements Listener
{

	public void trigger(Object param)
	{
		ECResponse resp = (ECResponse) param;
		Component parent = null;
		Object currentReq = ClientContext
				.removeKey(ClientConst.CURRENT_REQUESTOR);
		if (currentReq != null)
		{
			parent = (Component) currentReq;
		}
		Object waitDialog = ClientContext
				.removeKey(ClientConst.CURRENT_WAITING_DIALOG);
		if (waitDialog != null)
		{
			JDialog dialog = (JDialog) waitDialog;
			dialog.setVisible(false);
			dialog.dispose();
		}
		if (resp.getStatusCode() == null || resp.getStatusCode() != 200)
		{
			CommonDialog.showErrorMessageDialog(parent, resp.getResponseText()) ;
			return; 
		}
	}

}
